import { SEARCH_FOCUS, SEARCH_BLUR, GET_LIST, MOUSE_ENTER, MOUSE_LEAVE, CHEANGR_PAGE } from './constants';
import { fromJS } from 'immutable';

const defaultState = fromJS({
  focused: false,
  mouseIn: false,
  list: [],
  page: 1,
  totalPage: 1
})

export default (state = defaultState, action) => {
  
  if(action.type === SEARCH_FOCUS) return state.set('focused', true);
  
  if(action.type === SEARCH_BLUR) return state.set('focused', false);

  if(action.type === MOUSE_ENTER) return state.set('mouseIn', true);

  if(action.type === MOUSE_LEAVE) return state.set('mouseIn', false);

  if(action.type === CHEANGR_PAGE) return state.set('page', action.page);

  if(action.type === GET_LIST) return state.merge({ list: action.data, totalPage: action.totalPage })

  return state;
}